package iss.java;

import iss.java.list.MyList;
import iss.java.list.Node;
/**
 * Created by wenke on 2016/9/16.
 */
public class Main_B {
    public static void main(String[] args) throws InterruptedException{
        // TODO: Write a multithreaded testcase against requirement B.
        // NOTE: Testcase for requirement C is not required.
        MyList list=new MyList();
        Thread thread1=new Thread(){
            public void run(){
                Node newNode=list.getHead();
                for(int i=0;i<1000;i++) {
                    list.insert(newNode,i);
                    newNode=newNode.getNext();
                }
            }
        };
        Thread thread2=new Thread(){
            public void run(){
                Node newNode=list.getHead();
                for(int i=0;i<1000;i++) {
                    list.insert(newNode,i);
                    newNode=newNode.getNext();
                }
            }
        };
        Thread thread3=new Thread(){
            public void run(){
                Node newNode=list.getHead().getNext();
                for(int i=0;i<1000;i++){
                    list.remove(newNode);
                    newNode=newNode.getNext();
                }
            }
        };
        Thread thread4=new Thread(){
            public void run(){
                Node newNode=list.getTail().getPrev();
                for(int i=0;i<1000;i++){
                    list.remove(newNode);
                    newNode=newNode.getPrev();
                }
            }
        };
        thread1.start();
        thread2.start();
        Thread.sleep(10000);
        System.out.println("遍历list:");
        Node node=list.getHead();
        for(int i=0;i<list.getSize();i++){
            node=node.getNext();
            System.out.print(node.getData()+"\n");
        }
        System.out.println("倒序遍历list:");
        node=list.getTail();
        for(int i=0;i<list.getSize();i++){
            node=node.getPrev();
            System.out.print(node.getData()+"\n");
        }

        System.out.println("下面进行删除操作");
        thread3.start();
        thread4.start();
        Thread.sleep(10000);
        System.out.println("删除后遍历list:");
        node=list.getHead();
        for(int i=0;i<list.getSize();i++){
            node=node.getNext();
            System.out.print(node.getData()+"\n");
        }
        System.out.println("删除后倒序遍历list:");
        node=list.getTail();
        for(int i=0;i<list.getSize();i++){
            node=node.getPrev();
            System.out.print(node.getData()+"\n");
        }
    }
}
